#include <glib.h>

static void _queue_foreach_func(gpointer data, gpointer       user_data)
{
    g_print("user_data:%s, data:%d \n", (gchar *)user_data, GPOINTER_TO_INT(data));
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    gint ret1 = 0, ret2 = 0, ret3 = 0;

    q = g_queue_new();

    g_queue_push_tail(q, GINT_TO_POINTER(1));
    g_queue_push_tail(q, GINT_TO_POINTER(2));
    g_queue_push_tail(q, GINT_TO_POINTER(3));
    // result: 1-2-3

    g_queue_foreach(q, _queue_foreach_func, "Queue-push");

    // pop
    ret1 = GPOINTER_TO_INT(g_queue_pop_head(q));
    ret2 = GPOINTER_TO_INT(g_queue_pop_head(q));
    ret3 = GPOINTER_TO_INT(g_queue_pop_head(q));

    g_print("ret1:%d, ret2:%d, ret3:%d \n", ret1, ret2, ret3);
    g_queue_free(q);

    return 0;
}